package com.qf.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qf.pojo.DtsIssue;
import com.qf.service.DtsIssueService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * projectName:workspace_6
 * author:hyn
 * time:2021/12/5 16:46
 * description:商场管理 常见问题
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/admin/issue")
public class AdminIssueController {
    @Autowired
    private DtsIssueService issueService;
    //通用问题列表
    @RequestMapping("list")
    public Object list(String question,
                       @RequestParam(name = "page",required = false,defaultValue = "1") Integer page,
                       @RequestParam(name = "limit",required = false,defaultValue = "20") Integer limit,
                       @RequestParam(name = "sort",required = false,defaultValue = "add_time") String sort,
                       @RequestParam(name = "order",required = false,defaultValue = "desc") String order
    ){
        IPage<DtsIssue> articleList = issueService.findIssueAllList(question,page,limit,sort,order);

        Map<String, Object> data = new HashMap<>();
        data.put("total",articleList.getTotal());
        data.put("items",articleList.getRecords());
        return ResponseUtil.ok(data);
    }
    //通用问题添加
    @RequestMapping("create")
    public Object create(@RequestBody DtsIssue issue){
        if(issue == null){
            return ResponseUtil.badArgument();
        }
        return issueService.insert(issue);
    }
    //通用问题修改
    @RequestMapping("update")
    public Object update(@RequestBody DtsIssue issue){
        if(issue == null){
            return ResponseUtil.badArgument();
        }
        return issueService.update(issue);
    }
    //通用问题删除
    @RequestMapping("delete")
    public Object delete(@RequestBody DtsIssue issue){
        if(issue == null){
            return ResponseUtil.badArgument();
        }
        return issueService.delete(issue);
    }
}
